import { Component, OnInit, Injector } from '@angular/core';
import { BaseComponentConfig, ExpressionPair, Compare, AndOr } from '../..';
import { NgZorroPageBaseComponent } from '../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component';
import { SignalRService } from '../../core/service/singnalr-service';
import { NavigationExtras } from '@angular/router';

@Component({
  selector: 'app-game-hall',
  templateUrl: './game-hall.component.html',
  styleUrls: ['./game-hall.component.scss']
})
export class GameHallComponent extends NgZorroPageBaseComponent implements OnInit {

  constructor(injector: Injector,
    private signalrService: SignalRService) {
    super(injector,
      new BaseComponentConfig(
        "DrillRecord/GetCanPlayDrillRecord",
        "",
        "",
        "",
        "",
        "id",
        "",
        "")
    );
    this.listEntities.pageSize = 5;
  }

  ngOnInit() {
    this.IniObserver.subscribe(e => {
      this.getEntityList();
    });
    this.listSearchValue = new Array<ExpressionPair>(
      new ExpressionPair('asdfasdf', '', Compare.Contains, AndOr.And)
    );
  }

  async canJoinRoom(roomId: number) {
    const result = await this.httpService.get<boolean>(`DrillRecord/CanJoinRoom?recordId=${roomId}`);
    if (result) {
      const navigationExtras: NavigationExtras = {
        queryParams: { 'id': roomId}
      };
      this.router.navigate(['/app/mydrill/hall/room'], navigationExtras);
    } else {
      this.message.error('你有未完成的演练，不能再加入其他演练！');
    }
  }
  getIndex(index: number) {
    index += 1;
    let reslut = index > 3 ? index % 3 : index;
    reslut = reslut === 0 ? reslut + 1 : reslut;
    return reslut;
  }
}
